package team.tunan.mapper;

import net.sf.jsqlparser.expression.operators.relational.Matches;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import team.tunan.entity.Game;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sqx
 * @since 2024-01-01
 */
public interface GameMapper extends BaseMapper<Game> {

    int addGame(@Param("game") Game game);

    List<Game> selectGame();

    //    @Select("select match_id,mname from game where status in (0,1)")
    List<Map<String,Object>> getGameInfo(@Param("isAll") Integer isAll);


    @Select("select * from game ")
    List<Map<String,Object>> getGameInfoTwo();


    @Select(("select * from game where match_id = #{gid}"))
    Game getGame(@Param("gid") Integer gid);

    @Insert("update game set mname = #{game.mname},matchAddress = #{game.matchAddress},matchInfo = #{game.matchInfo} ,status = #{game.status} " +
            "where match_id = #{game.matchId}")
    int updateGame(@Param("game") Game game);

    /**
     * 查看比赛还有没有未进行完的场次(包括创建还未开启，暂停，进行中)
     * @param gid
     * @return
     */
    @Select("select * from matches where match_id = #{gid} and m_status in (0,1,3) ")
    List<Matches> haveMatches(@Param("gid") Integer gid);

    @Update("update user set player_select = 0 ,matchId = 0,roundNum = 0 where matchId = #{gid}")
    int endGame(@Param("gid") Integer gid);


}
